﻿Imports System.Data.SqlClient

Public Class ConexionSQL
    Protected cnn As New SqlConnection
    Protected cadena As String = "Data Source=GULDABD01;Initial Catalog=BD_SistemaInformacionPrueba;Integrated Security=True"
    Protected Function conectarSQL()
        Try
            'cnn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\AsistenciaBD\Asistencia.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
            cnn = New SqlConnection(cadena)
            'cnn = New SqlConnection("Data Source=200.62.213.29;Initial Catalog=BD_SistemaIntegral;Integrated Security=True")
            cnn.Open()
            Return True
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
    Protected Function obtenerConexionSQL() As SqlConnection
        Try
            'cnn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\AsistenciaBD\Asistencia.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")
            cnn = New SqlConnection(cadena)
            'cnn = New SqlConnection("Data Source=200.62.213.29;Initial Catalog=BD_SistemaIntegral;Integrated Security=True")
            Return cnn
        Catch ex As Exception
            MsgBox(ex.Message)
            Return Nothing
        End Try
    End Function
    Protected Function desconectarSQL()
        Try
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
            Return False
        End Try
    End Function
End Class
